package com.yileiqian.util;

public class Queue<T> {

	private Node<T> begin;
	private Node<T> end;

	public Queue() {

	}

	public boolean hasNext() {
		return begin != null;
	}

	public void enqueue(T value) {
		if (begin == null) {
			begin = new Node<T>(value);
			end = begin;
		} else {
			Node<T> node = new Node<T>(value);
			end.setNext(node);
			end = node;
		}
	}

	public T dequeue() {
		if (begin == null) {
			throw new NullPointerException();
		} else {
			T value = begin.getValue();
			begin = begin.next();
			return value;
		}
	}
}

